package ltd.smallwang.infrastructure.exception;

import com.alibaba.cola.exception.BizException;
import com.alibaba.cola.exception.SysException;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
public enum CommonErrorCode {
  /**
   * Success common error code.
   */
  SUCCESS("0000", "success", HttpStatus.OK),
  /**
   * The System error.
   */
  SYSTEM_ERROR("0001", "system error", HttpStatus.INTERNAL_SERVER_ERROR),
  /**
   * The Vertical privilege escalation.
   */
  VERTICAL_PRIVILEGE_ESCALATION("0002", "vertical privilege escalation",
      HttpStatus.FORBIDDEN),
  /**
   * The Lateral privilege escalation.
   */
  LATERAL_PRIVILEGE_ESCALATION("0003", "lateral privilege escalation",
      HttpStatus.FORBIDDEN),

  /**
   * The Concurrent restrictions.
   */
  CONCURRENT_RESTRICTIONS("0004", "concurrent restrictions", HttpStatus.BAD_REQUEST);

  private static final String BASE_CODE = "0000";

  private final String errorCode;

  private final String errorMessage;

  private final HttpStatus httpStatus;

  CommonErrorCode(String errorCode, String errorMessage, HttpStatus httpStatus) {
    this.errorCode = BASE_CODE + errorCode;
    this.errorMessage = errorMessage;
    this.httpStatus = httpStatus;
  }

  public BizException buildBizException() {
    return new BizException(errorCode, errorMessage);
  }

  public SysException buildSysException() {
    return new SysException(errorCode, errorMessage);
  }
}
